package com.bookstore.dao.impl;

import com.bookstore.dao.NoticeDao;
import com.bookstore.entity.Notice;

import java.util.List;

public class NoticeDaoImpl implements NoticeDao {
    @Override
    public int insert(Notice notice) {
        String sql = "INSERT INTO `T_notice`(`title`,`details`,`n_time`) VALUES (?, ?, ?)";
        return 0;
    }

    @Override
    public int delete(Integer noticeId) {
        String sql = "DELETE FROM `T_notice` WHERE `n_id`=?";
        return 0;
    }

    @Override
    public int update(Notice notice) {
        int result = 0;
        String sql = "UPDATE `T_notice` SET";
        StringBuilder sb = new StringBuilder(sql);
        int flag=0;
        if(notice==null){
            return result;
        }
        if(notice.getTitle()!=null){
            flag=1;
            sb.append(" `title`=?");
        }
        if(notice.getDetails()!=null){
            if(flag!=0){
                sb.append(",");
            }
            sb.append(" `details`=?");
            flag=1;
        }
        if(notice.getnTime()!=null){
            if(flag!=0){
                sb.append(",");
            }
            sb.append(" `n_time`=?");
            flag=1;
        }
        return 0;
    }

    @Override
    public List<Notice> queryNotice(Notice notice) {
        String sql = "SELECT * FROM `T_notice` WHERE  1=1";
        StringBuilder sb = new StringBuilder(sql);
        if(notice.getnId()!=null){
            sb.append(" AND `n_id`=?");
        }
        if(notice.getTitle()!=null){
            sb.append(" AND `title`=?");
        }
        if(notice.getDetails()!=null){
            sb.append(" AND `details`=?");
        }
        if(notice.getnTime()!=null){
            sb.append(" AND `n_time`=?");
        }
        return null;
    }
}
